﻿import com.dmotiko.mirador.*
import com.dmotiko.general.*
import mx.utils.Delegate;

class MiradorBtnBar
extends BaseClip {
	private var aBtns:Array;
	private var aData:Array;
	private var activeBtn:MiradorBtn;
		
	private function bindBtn(btn):Void {
		for (var i:Number = 0; i < aBtns.length; i++){
			var _btn = aBtns[i];
			if(btn == _btn){
				btn.setData( aData[i] );
				btn.addEventListener( BaseClipEvent.CHANGED, Delegate.create( this, btnSelected ));
			}
		}
	}
	
	private function btnSelected( evnt ):Void	{
		if ( activeBtn == evnt.target ) return;
		activeBtn.setActive( false );
		activeBtn = evnt.target;
		dispatchEvent( { type: BaseClipEvent.CHANGED, target: this, data: evnt.data } );
	}
	
	public function childLoaded(evnt):Void {
		bindBtn(evnt.target);
	}
	
	public function getActiveBtn():MiradorBtn { return activeBtn; }
	public function reset():Void {
		this.activeBtn.setActive(false, true);
		this.activeBtn.onRollOut();
		this.activeBtn = undefined;
	}
	
	public function getButtons():Array { return aBtns; }
	
	public function getButton( value ):MiradorBtn {
		for (var i:Number = 0; i < aBtns.length; i++) {
			if ( aBtns[i].getData() == value ) return aBtns[i];
		}
	}
	
}